import Vue from 'vue'
import VueRouter from 'vue-router'
import store from './../store'

import Home from '../views/Home/Home.vue'
import FoodCategory from '../views/FoodCategory/FoodCategory.vue'
import Login from '../views/Login/Login.vue'
import Register from '../views/Register/Register.vue'
import Order from '../views/Order/Order.vue'
import Payment from '../views/Order/Payment/Payment.vue'
import Paid from '../views/Order/Paid/Paid.vue'
import FoodDetail from '../views/FoodDetail/FoodDetail.vue'
import Personal from '../views/Personal/Personal.vue'
import Address from '../views/Personal/Address/Address.vue'
import HistoryOrder from '../views/Personal/HistoryOrder/HistoryOrder.vue'
import PersonInformation from '../views/Personal/PersonInformation/PersonInformation.vue'
import RedBag from '../views/Personal/RedBag/RedBag.vue'
import ShoppingCart from '../views/ShoppingCart/ShoppingCart.vue'
import Evaluate from '../views/Evaluate/Evaluate.vue'
import OrderDetail from '../views/OrderDetail/OrderDetail.vue'
import OrderDetailForLook from '../views/OrderDetailForLook/OrderDetailForLook.vue'
import Vip from "../views/Personal/Vip/Vip";
import FaceRegister from '../views/FaceRegister/FaceRegister.vue'
import CustomerService from "../views/Personal/CustomerService/CustomerService";

Vue.use(VueRouter)

const routes = [{
		path: '/',
		name: 'Home',
		component: Home
	},
	{
		path: '/login',
		name: 'Login',
		component: Login,
		meta: {
			keepAlive: true
		}
	},
	{
		path: '/register',
		name: 'Register',
		component: Register,
		meta: {
			keepAlive: true
		}

	},
	{
		path: '/faceRegister',
		name: 'FaceRegister',
		component: FaceRegister,
		meta: {
			keepAlive: true
		}
	},
	{
		path: '/personal',
		name: 'Personal',
		component: Personal,
		children:[
			{
				path: '/personal/address',
				name: 'PersonalAddress',
				component: Address
			},
			{
				path: '/personal/historyOrder',
				name: 'PersonalHistoryOrder',
				component: HistoryOrder
			},
			{
				path: '/personal/personInformation',
				name: 'PersonalPersonInformation',
				component: PersonInformation
			},
			{
				path: '/personal/redBag',
				name: 'PersonalRedBag',
				component: RedBag
			},
			{
				path: '/personal/vip',
				name: 'Vip',
				component: Vip
			},
			{
				path: '/personal/customerService',
				name: 'CustomerService',
				component: CustomerService
			},
		],
		redirect:'/personal/personInformation'
	},
	{
		path: '/foodcategory',
		name: 'FoodCategory',
		component: FoodCategory
	},
	{
		path: '/fooddetail',
		name: 'FoodDetail',
		component: FoodDetail
	},
	{
	  path: '/shoppingCart',
	  name: 'ShoppingCart',
	  component: ShoppingCart,
	},
	{
	  path: '/order',
	  name: 'Order',
	  component: Order,
	},
	{
		path: '/order/payment',
		name: 'Payment',
		component: Payment
	},
	{
	  path: '/order/paid',
	  name: 'Paid',
	  component: Paid,
	},
	{
	  path: '/evaluate',
	  name: 'Evaluate',
	  component: Evaluate,
	},
	{
		path: '/orderdetail',
		name: 'OrderDetail',
		component: OrderDetail,
	},
	{
		path: '/orderdetailforlook',
		name: 'OrderDetailForLook',
		component: OrderDetailForLook,
	},
]

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
	mode: 'history',
	base: process.env.BASE_URL,
	routes
})

router.beforeEach((to,from,next)=>{
	let pass = ['Home','Login','Register','FoodCategory','FoodDetail'];
	if(pass.indexOf(to.name) == -1){
		if(!store.getters.getisLogin){
			next({
				name: 'Login',
			})
		}else{
			next();
		}
	}else{
		next();
	}
	
});

export default router
